package com.woniuxy.qiantai.config;

import com.woniuxy.qiantai.interceptors.JwtInterceptor;
import com.woniuxy.qiantai.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    JwtInterceptor jwtInterceptor;

    @Autowired
    LoginInterceptor loginInterceptor;

//    //直接注册一些ViewController
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        //WebMvcConfigurer.super.addViewControllers(registry);
//
//        //配置  访问urlPath时对应的视图模板
//        registry.addViewController("/").setViewName("index");
//        registry.addViewController("/index").setViewName("index");
//        registry.addViewController("/index.html").setViewName("index");
//
//    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //拦截器按照注册的先后顺序执行

        registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/**");

//        registry.addInterceptor(loginInterceptor)
//                .addPathPatterns("/myCart.html")
//                .addPathPatterns("/cart/**")
//        ;

    }
}
